<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
    <title>用户登录</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body onload="loadInit()">

<div class="layui-container">
    <br><br><br><br><br><br>
    <br><br><br><br><br><br>
    <br><br><br><br><br><br>
    <br><br><br><br><br><br>
    <fieldset class="layui-elem-field">
        <legend><strong>用户登录</strong></legend>
        <div class="layui-field-box">

            <div class="layui-row">

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">账号</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="phone-focus" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="password-focus" name="password" lay-verify="email" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <button type="button" onclick="loginS()" class="layui-btn layui-btn-radius">登录</button>
                        </div>
                    </div>
                </div>


            </div>


        </div>
    </fieldset>




</div>

<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/js/utils.js}"></script>
<script th:src="@{/js/token_filter.js}"></script>
<script>

    function loadInit(){
        layui.use('layer',function(){
            let token = layui.data("tokens").token;
            layui.$.ajax({
                url:"https://common.mengqizhang.xyz/system/ct",
                data:null,
                type:"GET",
                headers:{'Accept':'application/json','token':token},
                dataType:"JSON",
                contentType:"application/json;charset=UTF-8",
                success:function(data){
                    let code = data.code;
                    console.log(data);
                    if(code == 200) {
                        location.href = "https://common.mengqizhang.xyz/index/";
                    }
                },
                error:function(data){
                    layui.$.alert('发生未知错误',data.msg);
                }
            });
        })

    }

    function loginS(){
        layui.use('layer',function(){
            let $ = layui.$;
            let phone = $.trim($("input[name='phone']").val());
            let password = $.trim($("input[name='password']").val());
            if(isEmpty(phone)){
                layer.msg('账号不能为空', function(){
                    setTimeout("$('#phone-focus').focus()",500);
                });
                return false;
            }
            if(isEmpty(password)){
                layer.msg('密码不能为空', function(){
                    setTimeout("$('#password-focus').focus()",500);
                });
                return false;
            }

            const data = {
                "loginName":phone,
                "passWord":password,
                "type": "pwd"
            };

            layui.$.ajax({
                url:"https://common.mengqizhang.xyz/system/login",
                data:JSON.stringify(data),
                type:"POST",
                dataType:"JSON",
                contentType:"application/json;charset=UTF-8",
                success:function(data){
                    let code = data.code;
                    if(code == 200){
                        layer.msg("登录成功", {icon:1,time:1500, shade:0.4}, function (){
                            layui.data("tokens", {
                                key: "token",
                                value: data.data
                            });
                            location.href = "https://common.mengqizhang.xyz/index/";
                        });
                    }else{
                        layer.msg(data.msg);
                    }
                },
                error:function(data){
                    layui.$.alert('发生未知错误',data.msg);
                }
            });


        });
    };




</script>
</body>
</html>